//package com.origin.learn.flume.service.impl;
//
//import com.origin.learn.flume.bean.*;
//import com.origin.learn.flume.service.Agent;
//import lombok.extern.slf4j.Slf4j;
//
//import java.util.List;
//import java.util.Optional;
//import java.util.Properties;
//
///**
// * @Description:
// * @Date: 2020/1/8
// * @Time: 14:07
// * @Created by:   dingtao
// * @Modified by:
// * @Modified at:
// */
//@Slf4j
//public abstract class AbstractAgent implements Agent {
//
//    protected AbstractAgent() {
//    }
//
//    /**
//     * 根据
//     *
//     * @return
//     */
//    @Override
//    public boolean generateAgentProperties() {
//        try {
//            generateAgentComponentProperties();
//            sourceList().forEach(this::generateComponentProperties);
//            channelList().forEach(this::generateComponentProperties);
//            sinkList().forEach(this::generateComponentProperties);
//            return true;
//        } catch (Exception e) {
//            log.error("创建agent组件信息失败\nCaused By:\n" + e.getCause());
//            return false;
//        }
//    }
//
//    @Override
//    public abstract boolean generateComponentProperties(FlumeComponent component);
//
//    private void generateAgentComponentProperties() {
//        try {
//            StringBuilder stringBuilder = new StringBuilder();
//            sourceList().forEach(source -> stringBuilder.append(source.name()).append(", "));
//            stringBuilder.deleteCharAt(stringBuilder.length() - 1);
//            agentProperty().put(agent().agentName() + "." + FlumePropertyConstant.Source.SOURCES, stringBuilder.toString());
//            stringBuilder.delete(0, stringBuilder.length());
//
//            channelList().forEach(channel -> stringBuilder.append(channel.name()).append(", "));
//            stringBuilder.deleteCharAt(stringBuilder.length() - 1);
//            agentProperty().put(agent().agentName() + "." + FlumePropertyConstant.Channel.CHANNELS, stringBuilder.toString());
//            stringBuilder.delete(0, stringBuilder.length());
//
//            sinkList().forEach(sink -> stringBuilder.append(sink.name()).append(", "));
//            stringBuilder.deleteCharAt(stringBuilder.length() - 1);
//            agentProperty().put(agent().agentName() + "." + FlumePropertyConstant.Sink.SINKS, stringBuilder.toString());
//        } catch (Exception e) {
//            log.error("创建agent组件信息失败\nCaused By:\n" + e.getCause());
//        }
//    }
//
////    @Override
////    public abstract boolean generateSourceProperties(FlumeSource source);
////
////    @Override
////    public abstract boolean generateChannelProperties(FlumeChannel channel);
////
////    @Override
////    public abstract boolean generateSinkProperties(FlumeSink sink);
//
////    private boolean generateAgentComponents(List<FlumeComponent> components, Function<List<FlumeComponent>, String> function){
////        String componentString = function.apply(components);
////
////        return true;
////    }
//
//
//    @Override
//    public abstract FlumeAgent agent();
//
//    @Override
//    public List<FlumeSource> sourceList() {
//        Optional<FlumeAgent> agent = Optional.of(agent());
//        return agent.get().sources();
//    }
//
//    @Override
//    public List<FlumeChannel> channelList() {
//        Optional<FlumeAgent> agent = Optional.of(agent());
//        return agent.get().channels();
//    }
//
//    @Override
//    public List<FlumeSink> sinkList() {
//        Optional<FlumeAgent> agent = Optional.of(agent());
//        return agent.get().sinks();
//    }
//
//    /**
//     * 获取Flume agent的Property配置实例
//     *
//     * @return
//     */
//    @Override
//    public abstract Properties agentProperty();
//
//
//    //    @Override
////    public String getPropertyString() {
////        StringBuilder stringBuilder = new StringBuilder();
////        String agentName = this.agent.agentName();
////
////        List<FlumeSource> source = this.agent.sources();
////        String sourceName = source.name();
////        stringBuilder.append(agentName)
////                .append(FlumePropertyConstant.SOURCES)
////                .append(FlumePropertyConstant.EQUALS)
////                .append(sourceName)
////                .append(FlumePropertyConstant.LINE_FEED);
////
////        FlumeChannel channel = this.flumeProperty.channels();
////        String channelName = channel.name();
////        stringBuilder.append(agentName)
////                .append(FlumePropertyConstant.CHANNELS)
////                .append(FlumePropertyConstant.EQUALS)
////                .append(channelName)
////                .append(FlumePropertyConstant.LINE_FEED);
////
////        FlumeSink sink = this.flumeProperty.sink();
////        String sinkName = sink.name();
////        stringBuilder.append(agentName)
////                .append(FlumePropertyConstant.SINKS)
////                .append(FlumePropertyConstant.EQUALS)
////                .append(sinkName)
////                .append(FlumePropertyConstant.LINE_FEED);
////        try {
////            stringBuilder.append(this.getPropertyString(agentName, source));
////            stringBuilder.append(this.getPropertyString(agentName, channel));
////            stringBuilder.append(this.getPropertyString(agentName, sink));
////        }catch (Exception e){
////            e.printStackTrace();
////        }
////
////        return stringBuilder.toString();
////    }
//
//    @Override
//    public boolean writePropertyFile(String path) {
//        return false;
//    }
//
//}
